package com.ssy.lingxi.system.controller;

import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.system.dto.request.*;
import com.ssy.lingxi.system.dto.response.ImageVerifyCodeResponse;
import com.ssy.lingxi.system.dto.response.MiddlegroundUserDetailsResponse;
import com.ssy.lingxi.system.dto.response.MiddlegroundUserLoginResponse;
import com.ssy.lingxi.system.dto.response.MiddlegroundUserResponse;
import com.ssy.lingxi.system.entity.LoginResponse;
import com.ssy.lingxi.system.service.ImageVerifyCodeService;
import com.ssy.lingxi.system.service.MiddlegroundUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
/**
 * @menu 权限管理-中台用户管理
 * @author wrc
 * @date 2020/7/20
 */
@Api(tags = "中台用户管理")
@RestController
public class MiddlegroundUserController {

    @Autowired
    MiddlegroundUserService middlegroundUserService;

    @Autowired
    ImageVerifyCodeService imageVerifyCodeService;

    @ApiOperation(value = "中台管理平台用户列表")
    @GetMapping("/middleground/user/list")
    public Wrapper<PageData<MiddlegroundUserResponse>> middlegroundUserList(MiddlegroundUserRequest request) {
        return middlegroundUserService.middlegroundUserList(request);
    }


    @ApiOperation(value = "中台管理平台用户登录")
    @PostMapping("/middleground/user/login")
    public Wrapper<LoginResponse> middlegroundUserLogin(@RequestBody  MiddlegroundUserLoginRequest dtoRequest, HttpServletRequest request) {
        return middlegroundUserService.middlegroundUserLogin(request,dtoRequest);
    }

    @ApiOperation(value = "根据用户token获取用户信息")
    @GetMapping("/middleground/user/details")
    public Wrapper<MiddlegroundUserLoginResponse> middlegroundUserDetails(HttpServletRequest request) {
        return middlegroundUserService.middlegroundUserDetails(request);
    }




    @ApiOperation("获取验证码图片")
    @PostMapping("/image/verify/code")
    public Wrapper<ImageVerifyCodeResponse> getImageVerifyCode(@RequestBody @Valid ImageVerifyCodeRequest request) {
        return  imageVerifyCodeService.getImageVerifyCode(request);
    }



    @ApiOperation(value = "新增用户")
    @PostMapping("/middleground/user/add")
    public Wrapper middlegroundUserAdd(@RequestBody  MiddlegroundUserAddRequest request,HttpServletRequest httpServletRequest) {
        return middlegroundUserService.middlegroundUserAdd(httpServletRequest,request);
    }


    @ApiOperation(value = "修改用户")
    @PostMapping("/middleground/user/update")
    public Wrapper middlegroundUserUpdate(@RequestBody MiddlegroundUserUpdateRequest request) {
        return middlegroundUserService.middlegroundUserUpdate(request);
    }


    @ApiOperation(value = "修改用户状态")
    @PostMapping("/middleground/user/update/state")
    public Wrapper middlegroundUserUpdateState(@RequestBody MiddlegroundUserUpdateStateRequest request) {
        return middlegroundUserService.middlegroundUserUpdateState(request);
    }


    @ApiOperation(value = "用户信息详情")
    @GetMapping("/middleground/user/detailsById")
    public Wrapper<MiddlegroundUserDetailsResponse> middlegroundUserDetailsById(MiddlegroundUserDetailsRequest request) {
        return middlegroundUserService.middlegroundUserDetailsById(request);
    }


    @ApiOperation(value = "删除用户信息")
    @PostMapping("/middleground/user/delete")
    public Wrapper middlegroundUserDeleteById(@RequestBody MiddlegroundUserDetailsRequest request, HttpServletRequest httpServletRequest) {
        return middlegroundUserService.middlegroundUserDeleteById(request,httpServletRequest);
    }
}
